#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int isok(char *s) {
	int n = strlen(s);
	if (n & 1)
		return 0;
	int i;
	for (i = 0; i < n / 2; i++)
		if (s[i] != s[n - 1 - i])
			return 0;
	return 1;
}
void solve(char *s) {
	int len;
	while (isok(s)) {
		len = strlen(s);
		s[len / 2] = 0;
	}
	printf("%d\n", strlen(s));
}
int main(void) {
	char s[1000];
	int n;
	scanf("%d", &n);
	while (n--) {
		scanf("%s", s);
		solve(s);
	}
	return EXIT_SUCCESS;
}
